<?php
  require(dirname(__FILE__).'/global.php');
  
  $email = $_POST['useremail'];
  if(!isset($email))
  {
      $smarty->assign("code","verify.php");
      $smarty->display('login.html');
  }
  else
  {
      $userpass = $_POST['userpass'];
      require(ROOT.'/include/encrypt.class.php');
      $userpass = Encrypt::encrypt($userpass);
      
      $sql = "select UserID,UserName,UserGroup from talking_user where UserEmail = '$email' and UserPass = '$userpass'";
      $users = $db->query($sql);
      if(count($users) == 0)
      {
          echo '用户不存在！';
          exit();
      }
       
      $_SESSION['user']['id'] = $users[0]['UserID'];
      $_SESSION['user']['name'] = $users[0]['UserName']; 
      $_SESSION['user']['group'] = $users[0]['UserGroup'];
      
      $returnUrl = $_GET['ReturnUrl'];
      if(!isset($returnUrl))
      {                   
          header("Location: index.php");
      }
      else
      {
          $page = pathinfo($returnUrl,PATHINFO_BASENAME);
          if(($page == 'login.php')||($page == 'login')||($page == 'findpassword.php')||($page == 'findpassword'))
          {
              header("Location: index.php");
          }
          else
          {
              header("Location: $returnUrl");
          }
      }                              
  }
  $db->close();
?>